package com.geovis.emergency.spd.controller.pc;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.geovis.common.core.api.Result;
import com.geovis.common.core.controller.BaseController;
import com.geovis.common.mybatis.page.PageParam;
import com.geovis.emergency.spd.biz.pc.service.IPcDrillPlanResponseService;
import com.geovis.emergency.spd.biz.pc.service.IPcPlanResponseService;
import com.geovis.emergency.spd.biz.pc.service.IPcPlanStructureService;
import com.geovis.emergency.spd.entity.pc.entity.PcDrillPlanResponse;
import com.geovis.emergency.spd.entity.pc.entity.PcPlanStructure;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcPlanQueryDTO;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcPlanStructureByDrillDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 应急预案指挥模块 - 预案结构化 前端控制器
 * </p>
*
* @author Lonsho
* @since 2022-06-17
*/
@RestController
@RequestMapping("/pc/planStructure")
@RequiredArgsConstructor
@Api(value = "应急预案指挥模块 - 预案结构化接口", tags = "应急预案指挥模块 - 预案结构化接口")
@Slf4j
@Validated
public class PcPlanStructureController extends BaseController<IPcPlanStructureService> {

    private final IPcDrillPlanResponseService pcDrillPlanResponseService;
    @ApiOperation(value = "根据演练id 和灾害事件id 获取预案结构化文档", notes = "根据演练id 和灾害事件id 获取预案结构化文档")
    @PostMapping("/drill/getList")
    public Result<List<PcPlanStructure>> getList(@RequestBody PcPlanStructureByDrillDTO pcPlanStructureByDrillDTO) {

        List<PcPlanStructure> r=null;
        if(ObjectUtil.isNotEmpty(pcPlanStructureByDrillDTO.getDrillId())
                &ObjectUtil.isNotEmpty(pcPlanStructureByDrillDTO.getEventId()))
        {
            PcDrillPlanResponse pcDrillPlanResponse=pcDrillPlanResponseService.getOne(Wrappers.lambdaQuery(PcDrillPlanResponse.class)
                    .eq(PcDrillPlanResponse::getPcDrillId, pcPlanStructureByDrillDTO.getDrillId())
                    .eq(PcDrillPlanResponse::getPcDrillDisasterEventId, pcPlanStructureByDrillDTO.getEventId()));
            if(pcDrillPlanResponse!=null)
                r=baseService.list(Wrappers.lambdaQuery(PcPlanStructure.class)
                        .eq(PcPlanStructure::getPcPlanId, pcDrillPlanResponse.getPcPlanId()));
        }
        return Result.ok(r);
    }
}
